import java.util.Arrays;

public class MyCycleQueue {
    public int[] elem;
    public int front;
    public int rear;
    public MyCycleQueue(){
        elem=new int[10];
    }
    public void offer(int data){
        if(isFull()){
            elem=kuoRong();

        }
        elem[rear]=data;
        rear=(rear+1)%elem.length;
    }
    public int poll(){
        if(isEmpty()){
            return -1;
        }
        int val=elem[front];
        front=(front+1)%elem.length;
        return val;
    }
    public int peekFirst(){
        if(isEmpty()){
            return -1;
        }
        return elem[front];
    }
    public int peekLast(){
        if(isEmpty()){
            return -1;
        }
        if(rear==0){
            return elem[elem.length-1];
        }
        return elem[rear-1];
    }
    public boolean isEmpty(){
        if(rear==front){
            return true;
        }
        return false;
    }
    public boolean isFull(){
        if((rear+1)%elem.length==front){
            return true;
        }
        return false;
    }
    public int[] kuoRong(){
        return Arrays.copyOf(elem,elem.length*2);
    }
}
